package pl.edu.agh.iosr.gamblingzone.model;

import java.util.LinkedList;
import java.util.List;

import javax.persistence.AttributeOverride;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

@AttributeOverride(name="id",
		column=@Column(name="BETTING_SLIP_ID"))
@Entity(name="BETTING_SLIP")
public class BettingSlip extends IEntity {
	
	@Column(name="BETTING_SLIP_MONEY", nullable=false)
	private Long money = 0L;
	
	@Column(name="BETTING_SLIP_WAS_PAID", nullable=false)
	private boolean wasPaid = false;
	
	@ManyToOne
	@JoinTable(
			name = "USER_BETTINGSLIP",
			joinColumns = {@JoinColumn(name="BETTING_SLIP_ID")},
			inverseJoinColumns = {@JoinColumn(name="USER_ID")}
		)
	private User owner;
	
	@OneToMany(mappedBy="bettingSlip", cascade=CascadeType.ALL)
	@JoinColumn(name="BETTING_SLIP_ID")
	private List<Bet> bets = new LinkedList<Bet>();
	
	public Long getMoney() {
		return money;
	}
	public void setMoney(Long money) {
		this.money = money;
	}
	public boolean isWasPaid() {
		return wasPaid;
	}
	public void setWasPaid(boolean wasPaid) {
		this.wasPaid = wasPaid;
	}
	public User getOwner() {
		return owner;
	}
	public void setOwner(User owner) {
		this.owner = owner;
	}
	public void addBet(Bet b) {
		b.setBettingSlip(this);
		this.bets.add(b);
	}
	public List<Bet> getBets() {
		return bets;
	}
}
